import storage from '@/utils/ado-self/ado-storage';
import { getLocalVars } from '/lib/local/localUtil.js';

async function initWinVars() {
  const theme = window.location.href.indexOf('xvue_theme=dark') > -1 ? 'dark' : 'light'; // 本地环境
  window._adoPremise = {
    uc: {
      theme,
      languages: {},
    },
  };

  // 租户id
  const { token } = storage.get('visual_components_token') || {};
  if (token && typeof token === 'object') {
    window._adoPremise.tenantId = token.tenantId;
  }

  window.visualComp = {
    visualThemeClassName: `visualComponents_theme_${theme}`,
  };

  // 通过接口获取变量
  const localVars = await getLocalVars();
  window.localVars = localVars;
  window._adoPremise = {
    ...localVars._adoPremise,
    ...window._adoPremise,
  };
  return true;
}

initWinVars();
